package mybook;

import jgo.JGo;
import jgo.RouterPlugin;
import jgo.core.ConfigPlugin;
import jgo.plugins.StartupTimePlugin;
import jgo.plugins.jdbc.JdbcTemplatePlugin;
import jgo.plugins.jdbc.MySqlPlugin;
import jgo.plugins.middleware.CorsMiddleware;
import jgo.plugins.middleware.ErrorHandlingMiddleware;
import jgo.plugins.middleware.LoggingMiddleware;
import jgo.plugins.server.JavaHttpServerPlugin;
import jgo.plugins.server.NettyHttpServerPlugin;
import jgo.plugins.server.SimpleHttpServer;
import jgo.plugins.template.SimpleErrorHandlerPlugin;
import mybook.routes.BookRoutes;

public class App {
    public static void main(String[] args) {
        JGo gin = new JGo();
        gin.continueOnPluginInitError=(true);
        gin.use(new ConfigPlugin("config.propertie"))
        .use(new StartupTimePlugin())
           .use(MySqlPlugin.instance)
           .use(JdbcTemplatePlugin.instance)
           .use(new NettyHttpServerPlugin(8080))
           .use(new SimpleHttpServer(8001))
           .use(new JavaHttpServerPlugin(3000))
           .use(new RouterPlugin())
           .use(new SimpleErrorHandlerPlugin())
           
           //中间件
           .use(new LoggingMiddleware())
           .use(new ErrorHandlingMiddleware())
           .use(new CorsMiddleware());

        RouterPlugin router = gin.getPlugin(RouterPlugin.class);
        BookRoutes.configure(router);

        gin.run();

        System.out.println("应用已启动，访问 http://localhost:3000/books 获取图书列表");
    }
}